using System;
using System.Collections.Generic;
using System.Collections;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using System.Diagnostics;
namespace FilmekAdatbazis
{
    class vizs:DAL
    {
        private System.Data.DataSet dsfilm;
        private System.Data.SqlClient.SqlDataAdapter daGrid;
        private System.Data.SqlClient.SqlDataAdapter dafilm;
        private System.Data.SqlClient.SqlDataAdapter daAruk;
        private System.Data.DataSet dsArukGrid;
        public bool Err;
        private string sQuery;
        public vizs()
        {
            //if (!base.IsConnectCreated())
            //{
              //  Err = !base.MakeConnection();
            //}
            daAruk = new SqlDataAdapter();
            daAruk.TableMappings.Add("Table", "Szereplok");
            //daEgyAruSor = new SqlDataAdapter();
           // daEgyAruSor.TableMappings.Add("Table", "EgyAru");
            //			dsArukGrid = new DataSet("ArukGrid");
           // daGrid = new SqlDataAdapter();
           // daGrid.TableMappings.Add("Table", "ArukGrid");
        }

        public System.Data.SqlClient.SqlDataReader Tolt(ref string ErrM)
        {
            myDataReader = base.myExecuteReader("SELECT * FROM Felhasznlok", ref ErrM);
            return myDataReader;
        }
        public System.Data.DataSet AruGridTolt(ref string ErrM)
        {
            string sSQL = "CREATE TABLE #t1(FelhasznaloID int,ossz int)"+
            "select Felhasznaloid, count(kolcsonzid)as ossz  into #t2"+
    "from kolcsonzesek group by Felhasznaloid"+
            "select FelhasznaloNev From Felhasznalok f,into #t1 t"+

                
         "where f.felhasznaloid=t.felhasznaloid and ossz=(select max(ossz) from #t1)";
            dsArukGrid = base.myFillDataSetFromString(sSQL, "ArukGrid", ref daGrid, ref ErrM);
            return dsArukGrid;

        }      
        public System.Data.DataSet filmGridTolt(string sBetuk, ref string ErrM)
        {
            string sSQL = "SELECT FelhasznaloNev FROM Felhasznlok ";
           
            dsfilm = base.myFillDataSetFromString(sSQL, "felhaszn", ref dafilm, ref ErrM);
            return dsfilm;
        }
        public System.Data.DataSet FelhasznalokGridTolt(string tablaNev, ref string ErrM)
        {
            string sSQL = "SELECT FelhasznaloNev FROM Felhasznalok ";
            return base.FillDataSetFromSqlQuery(sSQL, tablaNev, ref ErrM);
        }

        public System.Data.SqlClient.SqlDataReader FelhasznaloLbTolt(ref string ErrM)
        {
            String query = "SELECT Felhasznlonev FROM Felhasznalok";
            return base.myExecuteReader(query, ref ErrM);
        }
        public static void ListBoxEpito(System.Windows.Forms.ListBox lb, System.Data.SqlClient.SqlDataReader DtReadcombo, ref ArrayList aKOD)
        {
            lb.Items.Clear();
            while (DtReadcombo.Read())
            {
                lb.Items.Add(DtReadcombo[1].ToString());
                aKOD.Add(DtReadcombo[0].ToString());
            }
            DtReadcombo.Close();

        }
        public vizs(ref bool Err)
		{
			if (!base.IsConnectCreated())
			{
				Err = !base.MakeConnection();
			}
			dafilm = new SqlDataAdapter();
			dafilm.TableMappings.Add("Table", "Szereplok");
		}

    }
}
